package caiwei.android.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import caiwei.android.R;
import caiwei.android.activity.base.ActivityFrame;
import caiwei.android.adapter.AdapterAppGrid;
import caiwei.android.controls.SlideMenuItem;
import caiwei.android.controls.SlideMenuView.OnSlideMenuListener;

/**
 * 应用程序主Activity
 * 
 * @author caiwei
 * @date2012-3-2
 * @version 1.0
 */
public class ActivityAppMain extends ActivityFrame implements
		OnSlideMenuListener
{
	private GridView mGridView;
	private AdapterAppGrid mAdapterAppGrid;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		hideTitleBackButton();
		appendMainBody(R.layout.main_body);
		initVariable();
		initView();
		bindData();
		createSlideMenu(R.array.SlideMenuActivityMain);
		initListener();
	}

	/**
	 * 初始化变量
	 */
	private void initVariable()
	{
		mAdapterAppGrid = new AdapterAppGrid(this);
	}

	/**
	 * 初始化View
	 */
	private void initView()
	{
		mGridView = (GridView) findViewById(R.id.gvAppGrid);
	}

	/**
	 * 绑定数据
	 */
	private void bindData()
	{
		mGridView.setAdapter(mAdapterAppGrid);
	}

	@Override
	public void onSlideMenuItemClick(View pView, SlideMenuItem pSlideMenuItem)
	{
		showMsg(pSlideMenuItem.getTitle());
	}

	/**
	 * 初始化监听器
	 */
	public void initListener()
	{
		mGridView.setOnItemClickListener(new OnAppGridItemClickListener());
	}

	/**
	 * 内部类，GridView选项的点击监听器
	 * 
	 * @author caiwei
	 * @date2012-3-6
	 * @version 1.0
	 */
	private class OnAppGridItemClickListener implements OnItemClickListener
	{

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id)
		{
			switch (position)
			{
			case 0:
				openActivity(ActivityGridBase.class);
				break;
			case 1:
				System.out.println("+++++++++1");
				break;
			case 2:
				System.out.println("+++++++++2");
				break;
			case 3:
				System.out.println("+++++++++3");
				break;
			case 4:
				System.out.println("+++++++++4");
				break;
			default:
				System.out.println("+++++++++5");
				break;
			}
		}
	}
}
